package com.yuhang.demo.controller;

import com.yuhang.demo.common.Result;
import com.yuhang.demo.entity.RoleEntity;
import com.yuhang.demo.entity.UserEntity;
import com.yuhang.demo.exceptionHandler.MyException;
import com.yuhang.demo.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 
 *
 * @author yyh
 * @email yyh@demo.com
 * @date 2021-07-16 16:45:01
 */
@RestController
@RequestMapping("demo/role")
@RefreshScope
public class RoleController {

    @Value("${app.name}")
    private String name;

    @Autowired
    private RoleService roleService;

    @GetMapping("/getName")
    public Result getName(){
        return Result.ok().data("name",name);
    }

    @PostMapping("/add")
    public Result addRole(@RequestBody RoleEntity roleEntity){

            Integer save = roleService.saveRole(roleEntity);

            if(save > 0){
                return Result.ok();
            }
            return Result.error();
    }

}
